﻿// ----------------------------------------------------------------------
//
// <copyright file="File_elper.cs" company="TheAcidToy Inc" Date="2012">
//     TheAcidToy is a registered trademark of TheAcidToy Inc. All right reserved, copywrited: 2012
// </copyright>
//
// ------------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Net;

public class File_elper
{
    public static string img_real(string file, string path)
    {
        if (File.Exists(path + file))
        {
            return path + file;
        }
        else
        {
            return "offline_icon.png";
        }
    }
    private static bool is_online = Online_Helper.IsConnectedToInternet();

    public static string chk_image(string file, string path, string url, Boolean cache)
    {
        if (cache)
        {
            if (File.Exists(path + file))
            {
                return path + file;
            }
            else if (is_online)
            {
                WebClient dl = new WebClient();
                dl.DownloadFile(url, path + file);
                return path + file;
            }
            else
            {
                return "offline_icon.png";
            }
        }
        else
        {
            if (File.Exists(path + file))
            {
                return path + file;
            }
            else if (is_online)
            {
                return url;
            }
            else
            {
                return "offline_icon.png";
            }
        }
    }
}
